﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace FuncWorks.Xna.UI.Menu
{
    public class ImageSelectItem : IMenuItem
    {
        public string Title { get; set; }
        public bool Enabled { get; set; }
        public bool Hidden { get; set; }
        public float Height { get; set; }

        Texture2D UnselectedImage;
        Texture2D SelectedImage;
        Texture2D DisabledImage;

		BlockAlignment align;
        Rectangle current;

		public ImageSelectItem(BlockAlignment alignment, Texture2D unselectedImage, Texture2D selectedImage, Texture2D disabledImage)
        {
            Title = "";
            Enabled = true;
            Hidden = false;
            align = alignment;
            UnselectedImage = unselectedImage;
            SelectedImage = selectedImage;
            DisabledImage = disabledImage;
            current = new Rectangle();
        }

        public void Activate() { }
        public void MoveLeft() { }
        public void MoveRight() { }

        public float CalculateHeight(TextStyle textStyle, bool selected)
        {
            Height = Enabled ? (selected ? SelectedImage.Height : UnselectedImage.Height) : DisabledImage.Height;
            return Height;
        }

        public void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, TextStyle textStyle, float currentY, Microsoft.Xna.Framework.Rectangle targetRectangle, bool selected)
        {
            Texture2D txt = Enabled ? (selected ? SelectedImage : UnselectedImage) : DisabledImage;

            current.Y = (int)currentY;
            current.Width = txt.Width;
            current.Height = txt.Height;

            switch (align)
            {
				case BlockAlignment.Left: current.X = targetRectangle.Left; break;
				case BlockAlignment.Right: current.X = targetRectangle.Right - txt.Width; break;
				default: current.X = targetRectangle.Center.X - (int)Math.Ceiling(txt.Width / 2.0f); break;
            }

            spriteBatch.Draw(txt, current, Color.White);
        }
    }
}
